﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using ClassLibrary.Entity;
using ClassLibrary.Data;
using System.Collections.Generic;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Label1.Text = DateTime.Now.ToString("dd/MM/yyyy");
            lbngay.Text = DateTime.Now.ToString("dd/MM/yyyy");
            if (Session[Global.SESSION_LOGGED_USER] == null)
            {
                lnkLogout.Visible = false;
            }
            else
            {
                loin.Visible = false;
                regis.Visible = false;
                lbTen.Text = ((TblUserAccount)Session[Global.SESSION_LOGGED_USER]).FirstName + " " + ((TblUserAccount)Session[Global.SESSION_LOGGED_USER]).LastName;
            }
           
        }
        UpdateShoppingCartSession();
        LoadCSS();
    }

    private void LoadCSS()
    {
       // string idCSS = Global.GetPageName(Request.ServerVariables["SCRIPT_NAME"].ToString());
        string idCSS = "";
        if ((idCSS == "Product.aspx?id=1"))
        {
            HyperLink1.Attributes.Add("class", "active");
        }
    }
    public void UpdateShoppingCartSession()
    {
        if (HttpContext.Current.Session[Global.SESSION_CART] != null)
        {
            List<TblBookingDetail> cartItems = (List<TblBookingDetail>)HttpContext.Current.Session[Global.SESSION_CART];

            int iQuantity = 0;
            double dAmount = 0;
            foreach (TblBookingDetail order in cartItems)
            {
                iQuantity += order.Quantity;
                //dAmount +=  order.TotalAmount;
                dAmount += order.Quantity * order.Price;
            }
            lbsoluong.Text = iQuantity.ToString();
            lblAmout.Text = dAmount.ToString("0,00.##");
        }
    }

    protected void lnkLogout_Click(object sender, EventArgs e)
    {
        Session[Global.SESSION_LOGGED_USER] = null;
        Response.Redirect("~/Default.aspx");
    }
}
